package fyf.com.carddesign.main.Login;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.dd.plist.NSArray;
import com.dd.plist.NSDictionary;
import com.dd.plist.NSObject;
import com.dd.plist.PropertyListParser;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import fyf.com.carddesign.BaseActivity;
import fyf.com.carddesign.Bll.UserBll;
import fyf.com.carddesign.MyUtl.MyUtl;
import fyf.com.carddesign.MyUtl.Tuple.Tuple;
import fyf.com.carddesign.MyUtl.Tuple.Tuple3;
import fyf.com.carddesign.R;
import fyf.com.carddesign.main.CarToonActivity;
import fyf.com.carddesign.main.SelectActivity;
import fyf.com.carddesign.main.admin.AdminMainActivity;

public class MainActivity extends BaseActivity {
    private MainActivity _parent;
    @BindView(R.id.tbb_ll_back)
    LinearLayout _llBack;
    @BindView(R.id.tbb_tv_name)
    TextView _tvTitleName;
    @BindView(R.id.main_et_name)
    EditText _etName;//用户名
    @BindView(R.id.main_et_pwd)
    EditText _etPwd;//密码
    @BindView(R.id.main_btn_login)
    Button _btnLogin;//登录
    @BindView(R.id.main_btn_register)
    Button _btnRegister;//注册
    private List<String> _list = new ArrayList<>();
    private List<String> _listSec = new ArrayList<>();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initViewContent();
    }

    //初始化
    private void initViewContent() {
        _parent = MainActivity.this;
        ButterKnife.bind(_parent);
        _llBack.setVisibility(View.INVISIBLE);
        _tvTitleName.setText("登录");


    }


    //校验登录信息
    private void checkLogin() {
        String name = _etName.getText().toString();
        String pwd = _etPwd.getText().toString();
        if (name.equals("")) {
            MyUtl.Toast(_parent, "登录名不能为空");
            return;
        }
        if (pwd.equals("")) {
            MyUtl.Toast(_parent, "登录密码不能为空");
            return;
        }
        //登录信息校验
        Tuple3<Boolean, String, Byte> tp = UserBll.getInstance(_parent).checkLoginMsg(name, pwd);
        if (!tp.get_t1()) {
            MyUtl.Toast(_parent, tp.get_t2());
            return;
        }
        if (tp.get_t3() == 0) {
            Intent intent = new Intent(_parent, AdminMainActivity.class);
            startActivity(intent);
            MyUtl.Toast(_parent, tp.get_t2());
        } else {

        }

    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_main;
    }

    /**
     * 注册按钮跳转
     *
     * @param view 按钮对象
     */
    @OnClick(R.id.main_btn_register)
    public void onRegister(View view) {
        Intent intent = new Intent(_parent, RegisterActivity.class);
        startActivity(intent);
    }

    @OnClick(R.id.main_btn_login)
    public void onLogin(View view) {
        checkLogin();
    }

    //看漫画按钮
    @OnClick(R.id.am_btn_cartoon)
    public void onCartoonClick(View view) {
        Intent intent = new Intent(this, SelectActivity.class);
        startActivity(intent);
    }

}
